<?php

namespace App\Console\Commands;

use App\Services\ReviewService;
use App\Services\SmsService;
use App\SysConfig;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class CreateSmsTasks extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create-sms-tasks';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $this->log('Command started');
        try {
            $smsService = new SmsService();
            $result = $smsService->createSmsTasks();
            $this->log('result: ' . json_encode($result, JSON_UNESCAPED_UNICODE));
        } catch (\Exception $e) {
            Log::error('[CreateSmsTasks::handle]', ['exception' => $e]);
        }
        $this->log('Command ended');
    }

    private function log($msg)
    {
        $now = now();
        $line = "[$now]$msg";
        $this->line($line);
    }
}
